<?php
/**
 * Created by PhpStorm.
 * User: l-eru
 * Date: 2018/7/9
 * Time: 9:03
 */

namespace App;


use Core\Log;

class Logger
{
    const CLOSED_VIA_UNKNOWN_DATA = 3;
    const CLOSED_VIA_TOKEN_ERROR = 4;
    const CLOSED_VIA_LINK_TWICE = 5;
    const CLOSED_VIA_REMOTE_COMMAND = 6;
    const CLOSED_VIA_HEART_DIE = 7;


    protected static $closeReason = [];

    /**
     * @param $tbMac string 探霸设备
     * @return Log
     */
    public static function cfgLog($tbMac)
    {
        return Log::getInstance($tbMac, Log::CONFIG_SERVER);
    }

    /**
     * @param $tbMac string  探霸设备
     * @return Log
     */
    public static function dataLog($tbMac)
    {
        return Log::getInstance($tbMac, Log::DATA_SERVER);
    }

    /**
     * redis键值，记录一些对应探霸的统计信息
     * @param $tbMac
     * @return string
     */
    public static function tb($tbMac)
    {
        return  date('Ymd') . 'LOG_' . $tbMac;
    }

    public static function getCloseReason($error)
    {
        if (empty(self::$closeReason)) {
            self::$closeReason = [
                self::CLOSED_VIA_UNKNOWN_DATA => '数据解析失败',
                self::CLOSED_VIA_TOKEN_ERROR => 'Token校验错误',
                self::CLOSED_VIA_LINK_TWICE  => '重复连接关闭旧连接',
                self::CLOSED_VIA_REMOTE_COMMAND => '外部指令',
                self::CLOSED_VIA_HEART_DIE => '心跳消失',
            ];
        }

        return self::$closeReason[$error] ?? 'Unknown Error';
    }
}